import requests
ip="http://192.168.153.128:8080"
#请求登录
mydata={"username":"admin","password":"123456"}
r=requests.post(f"{ip}/login",data=mydata)
print(r)
#区分开text json content的区别
#分别打印r中的内容
print(r.json())
myJSON=r.json()
token=myJSON["Admin-Token"]
print(token)

myheader={"Admin-Token":token}
print(myheader)
myText=r.text
print(myText)
myContent=r.content
print(myContent)


#实现登录、日志（5个）
#文件上传
#定义文件参数：'message_img'键来自抓包时的name对应的值，
#值是通过数组的形式传值，第一个参数是抓包时的'filename'对应的值，
#                      第二个参数是通过open打开一个文件，且是二进制读的形式，
#                      第三个参数是抓包时的文件类型
furl=r"D:\lius\pythonCode\APIAuto\datas\47586e5d4a4e39dbeb803ca09a8aece.png"
fileD={"file":("47586e5d4a4e39dbeb803ca09a8aece.png",
               open(furl,"rb"),
               "image/jpeg"
)}
r6=requests.post(f"{ip}/file/upload",headers=myheader,
                 files=fileD)
print(r6)
print(r6.json())
#新增日志
r1=requests.post(f"{ip}/OaLog/addOrUpdate",headers=myheader,json={
  "categoryId": "1",
  "content": "111",
  "tomorrow": "222",
  "question": "333",
  "batchId": "c8db676d8e66656af17b9c9332357b25",
  "sendUserIds": "",
  "sendDeptIds": "",
  "customerIds": "",
  "contactsIds": "",
  "businessIds": "",
  "contractIds": ""
})
print(r1)
print(r1.json())
#修改日志
r2=requests.post(f"{ip}/OaLog/addOrUpdate",headers=myheader,json={
  "logId": 145,
  "categoryId": "1",
  "content": "111",
  "tomorrow": "111",
  "question": "111",
  "batchId": "46144d8a2b3f162b457d4f589071cd45",
  "sendUserIds": "",
  "sendDeptIds": "",
  "customerIds": "",
  "contactsIds": "",
  "businessIds": "",
  "contractIds": ""
})
print(r2)
print(r2.json())
#获取日志
r3=requests.post(f"{ip}/OaLog/queryList",headers=myheader,json={
  "page": 1,
  "limit": 5
})
print(r3)
print(r3.json())
# 删除日志
id=r3.json()["data"]["list"][0]["logId"]
print(id)
sLogid={"logId":id}
r4=requests.post(f"{ip}/OaLog/deleteById",headers=myheader,data=sLogid)
print(r4)
print(r4.json())

